package com.shitou.shitouseckill.interceptor;

import com.shitou.shitoucommons.interceptor.LoginInterceptor;
import com.shitou.shitoucommons.opfeign.MemberFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * class detail:
 *
 * @author 石头人
 */
@SuppressWarnings("all")
@Component
public class SeckillLoginInterceptor extends LoginInterceptor implements HandlerInterceptor {

    @Autowired
    private MemberFeign memberFeign;


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        if ( handler instanceof HandlerMethod ){

            // 登陆校验  CheckUserLogin
            boolean isLogin = super.checkLogin(handler, request, response, memberFeign);

            // 权限校验  MemberAuthority
            boolean authority = super.checkAuthority(handler, request, response, memberFeign);

            // 秒杀权限校验  SeckillQuailfi
            boolean qualifi = checkQualifi(handler, request, response, memberFeign);

            // 接口限流校验  AccessLimit
            boolean accessLimit = super.checkCurrentLimiting(handler, request, response, memberFeign);

            // 权限集合校验
            return isLogin && qualifi && qualifi && accessLimit;
        }
        return true;
    }


    /**
     * 秒杀权限校验
     * @param handler
     * @param request
     * @param response
     * @param memberFeign
     * @return
     */
    public boolean checkQualifi(Object handler, HttpServletRequest request, HttpServletResponse response, MemberFeign memberFeign){

        return true;
    }
}
